package com.teradyne.merlin2.ui.server.service;

import java.util.ArrayList;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.teradyne.merlin2.business.service.webservice.BusinessDelegateServiceWSProxy;
import com.teradyne.merlin2.ui.client.service.OrdersService;
import com.teradyne.merlin2.ui.server.service.helper.OrderRequestHelper;
import com.teradyne.merlin2.ui.shared.models.OrderRequest;
import com.teradyne.merlin2.ui.shared.models.RequestStatus;
import com.teradyne.merlin2.ui.shared.models.Requests;

public class OrdersServiceImpl extends RemoteServiceServlet implements OrdersService {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3823334065363955642L;

	@Override
	public ArrayList<RequestStatus> getOrderRequestWithoutOrders(String customerNo, String customerSiteNo) {
		final BusinessDelegateServiceWSProxy customerService = new BusinessDelegateServiceWSProxy();

		Requests requests = new Requests();
		ArrayList<OrderRequest> listOrderRequest = new ArrayList<OrderRequest>();
		try {
			final com.teradyne.merlin2.business.service.webservice.OrderRequest[] businessListRequest = customerService.getOrderRequestWithoutOrders(customerNo, customerSiteNo);
			listOrderRequest = OrderRequestHelper.morph(businessListRequest);
			requests.setListOrderRequest(listOrderRequest);
			requests.extractRequestStatus();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return requests.getListRequestStatus();
	}

}
